package cn.iocoder.yudao.module.xkfz.util;

import com.alibaba.excel.annotation.ExcelProperty;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Description TODO
 * @Author ZWC
 * @Date 2024/5/23 17:21
 */
public class ExcelHeaderExtractor {

    public static List<HashMap<String, String>> getHeaderList(Class<?> dataClass) {
        List<HashMap<String, String>> headers = new ArrayList<>();
        Field[] fields = dataClass.getDeclaredFields();
        for (Field field : fields) {
            ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
            if (excelProperty != null) {
                String headName = excelProperty.value()[0];
                if (StringUtils.isNotBlank(headName)){
                    HashMap<String,String> headMap = Maps.newHashMapWithExpectedSize(2);
                    headMap.put("headName",headName);
                    headMap.put("field",field.getName());
                    headers.add(headMap);
                }
            }
        }
        return headers;
    }
}
